/**
 * Created by guosc on 2016/11/4 0004.
 */
define([
    'require',
    'angular',
    'underscore'
], function (require, angular, _) {
    return  function ($scope, Resource,GillionMsg,$rootScope,RuleSerivce) {
        RuleSerivce.promises().then(function () {
            $scope.ruleAssemblyId=$rootScope.currAssembly.id;
            Resource("/grule-manager/ruleAssembly/:id",{
                id:"@id"
            }).get({
                id:$scope.ruleAssemblyId
            },function(resp){
                $scope.ruleAssembly=resp;
            });
        });
        
        

        angular.element('.engine-tab li:first').trigger('click');
        var rulePackage=Resource("/grule-manager/ruleAssembly/:id",{
            id:"@id"
        });


        $scope.reset=function(){
            $scope.ruleAssembly=Resource("/grule-manager/ruleAssembly/:id",{
                id:"@id"
            }).get({
                id:$scope.ruleAssemblyId
            });
        }

        $scope.save=function(){
            angular.element('form[name="RuleAssemblyForm"]').scope().RuleAssemblyForm.verify().then(function(){
                rulePackage.update($scope.ruleAssembly,function(resp){
                    if(resp.success){
                        GillionMsg.alert("提示","保存成功！", function(){
                            RuleSerivce.setCurrentAssembly($scope.ruleAssembly);
                            angular.element(document).trigger('refresh.menu');
                        });
                    }
                })
            })
        };

    }
});


